home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 140 / Exame Informatica 140.iso / Revista / Flash / jogo.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2006-12-20  |  2.8 KB  |  112 lines

  1. function inicializarJogo()
  2. {
  3.    _root.createEmptyMovieClip("fundo2",_root.getNextHighestDepth());
  4.    _root.createEmptyMovieClip("fundo",_root.getNextHighestDepth());
  5.    _root.fundo2.attachMovie("fundoLonginquo","fundoLonginquo1",fundo2.getNextHighestDepth());
  6.    _root.fundo2.attachMovie("fundoLonginquo","fundoLonginquo2",fundo2.getNextHighestDepth());
  7.    _root.fundo.attachMovie("chao","chao1",fundo.getNextHighestDepth());
  8.    _root.fundo.attachMovie("chao","chao2",fundo.getNextHighestDepth());
  9.    _root.attachMovie("char","char",_root.getNextHighestDepth());
  10.    _root.fundo.cacheAsBitmap = true;
  11.    _root.fundo2.cacheAsBitmap = true;
  12.    _root.char.cacheAsBitmap = true;
  13.    _root.fundo.chao1.gotoAndStop(1);
  14.    _root.fundo.chao2.gotoAndStop(2);
  15.    _root.fundo2.fundoLonginquo1.gotoAndStop(1);
  16.    _root.fundo2.fundoLonginquo2.gotoAndStop(2);
  17.    _root.fundo2._x = 0;
  18.    _root.fundo2._y = 0;
  19.    _root.fundo._x = 0;
  20.    _root.fundo._y = Stage.height;
  21.    _root.fundo2.fundoLonginquo1._x = 0;
  22.    _root.fundo2.fundoLonginquo1._y = 0;
  23.    _root.fundo2.fundoLonginquo2._x = _root.fundo2.fundoLonginquo1._width;
  24.    _root.fundo2.fundoLonginquo2._y = 0;
  25.    _root.fundo.chao1._x = 0;
  26.    _root.fundo.chao1._y = 0;
  27.    _root.fundo.chao2._x = fundo.chao1._width;
  28.    _root.fundo.chao2._y = 0;
  29.    _root.char._xscale = char._yscale = charEscala;
  30.    _root.char._x = Stage.width / 2;
  31.    _root.char._y = Stage.height / 2;
  32. }
  33. function detectarTeclas()
  34. {
  35.    speed *= 0.85;
  36.    if(Key.isDown(37) && wall != "esq")
  37.    {
  38.       wall = "";
  39.       if(speed > - maxMove)
  40.       {
  41.          speed--;
  42.       }
  43.    }
  44.    else if(Key.isDown(39) && wall != "dir")
  45.    {
  46.       posicionarMapas();
  47.       wall = "";
  48.       if(speed < maxMove)
  49.       {
  50.          speed++;
  51.       }
  52.    }
  53.    if(Key.isDown(38) && !jumping)
  54.    {
  55.       wall = "";
  56.       jumping = true;
  57.    }
  58. }
  59. function moverPersonagem()
  60. {
  61.    var _loc2_ = _root.char;
  62.    if(speed > 0)
  63.    {
  64.       _loc2_.play();
  65.       _loc2_._xscale = charEscala;
  66.       if(_loc2_._x < Stage.width / 2)
  67.       {
  68.          _loc2_._x += speed;
  69.       }
  70.       else
  71.       {
  72.          _loc2_._x += speed / 50;
  73.          fundo2._x -= speed / 10;
  74.          fundo._x -= speed;
  75.       }
  76.    }
  77.    else if(speed < 0)
  78.    {
  79.       if(_loc2_._x <= 0)
  80.       {
  81.          _loc2_._x = 0;
  82.       }
  83.       else
  84.       {
  85.          _loc2_.play();
  86.          _loc2_._xscale = - charEscala;
  87.          _loc2_._x += speed;
  88.       }
  89.    }
  90.    if(speed < 1 && speed > -1)
  91.    {
  92.       speed = 0;
  93.       _loc2_.gotoAndStop(1);
  94.    }
  95. }
  96. var speed = 0;
  97. var maxMove = 15;
  98. var jumpSpeed = -10;
  99. var totalMapas = 6;
  100. var mapaActual = 2;
  101. var mapaActual2 = 2;
  102. var charEscala = 25;
  103. var wall = "";
  104. var jumping = true;
  105. var falling = true;
  106. inicializarJogo();
  107. onEnterFrame = function()
  108. {
  109.    detectarTeclas();
  110.    moverPersonagem();
  111. };
  112.